home *** CD-ROM | disk | FTP | other *** search
- Path: scream.ing.com!news
- From: "John C. Lund" <jlund@allaire.com>
- Newsgroups: alt.comp.lang.borland-delphi,comp.lang.c++
- Subject: Calling a C/C++ DLL from Delphi
- Date: Thu, 01 Feb 1996 11:00:26 -0600
- Organization: Allaire
- Message-ID: <3110F1AA.30A2@allaire.com>
- NNTP-Posting-Host: 206.144.133.15
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win95; I)
-
- I've written a simple Delphi program that calls a function in a
- C++ DLL I wrote. The DLL uses a "C" interface that I can call
- from other environments (like VB and C++). Although I can call
- the DLL function from my Delphi app, the parameters passed are
- garbage. I tried the same declarations I found in the Delphi
- libraries, but to no avail.
-
- For whatever reason it looks like the parameters are pushed and
- popped from the stack differently beween environments. I've
- tried declaring the function in Delphi with "stdcall", "cdecl",
- and "pascal".
-
- The parameters expected by the DLL are all LPSTR (i.e. char*), so
- I've tried passing PChar and an array of Char.
-
- Any suggestions?
-
-
- ***************
- Delphi SNIPPETS
- ***************
-
- {type, private}
- function GetFieldsForTable(
- pcharDataSourceName,
- pcharUsername,
- pcharPassword,
- pcharTableName: pChar
- ): integer;
-
- {implementation}
- function TODBCInformant.GetFieldsForTable;
- external 'patrik.dll' name 'GetFieldsForTable';
-
- {I call the function like this:}
- nIndex:= GetFieldsForTable(strpcopy(pcharBuiffer,'Test'),
- strpcopy(pcharBuiffer,''),
- strpcopy(pcharBuiffer,''),
- strpcopy(pcharBuiffer,'Employees'));
-
-
- ************
- C++ SNIPPETS
- ************
-
- // My C++ header (.H) declares the prototype like this:
- extern "C" INT FAR PASCAL EXPORT GetFieldsForTable(
- LPSTR lpszDataSourceName,
- LPSTR lpszUsername,
- LPSTR lpszPassword,
- LPSTR lpszTableName
- );
-
- /*
- My implementation uses the same format, and the function is named
- in the exports section of the .DEF file.
- */
-
-
- --
- // John C. Lund jlund@allaire.com http//:www.allaire.com/
-